; Exception class used in DEMO
.class SnackException
.super java/lang/Exception

.method <init>(Ljava/lang/String;)V
	aload_0		;"this"
	aload_1		;message as param
	invokespecial java/lang/Exception/<init>(Ljava/lang/String;)V
	return
.end method

.end class

.class ExceptionDemo
	
.method static noshSnack()V

.catch SnackException from begintry to endtry using SnackExceptionHandler
begintry:
	iconst_0
	ifgt endtry
	new SnackException
	dup
	ldc "Snack!"                                                         
	invokespecial SnackException/<init>(Ljava/lang/String;)V
	athrow
endtry:
	return
	
SnackExceptionHandler:
	getstatic java/lang/System/out Ljava/io/PrintStream;
	ldc "Snack got caught!"                                             
	invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V       
	return
	
.end method

.method static arrayOutOfBound([Ljava/lang/String;)V
.catch java/lang/ArrayIndexOutOfBoundsException from begintry to endtry using OutBoundHandler
	iconst_0
	istore_1	;init the loop counter
loop:	
	aload_0		;push array to stack top
	iload_1		;push current counter value
begintry:
	aaload
endtry:
	getstatic java/lang/System/out Ljava/io/PrintStream;
	swap
	invokevirtual java/io/PrintStream/println (Ljava/lang/String;)V
	iinc 1 1
	goto loop
endloop:                                                                 
OutBoundHandler:
	return		;just return, OutOfBounds is expected
.end method

.end class



